//https://leetcode.cn/problems/rotate-image/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    void rotate(vector<vector<int>>& matrix)
    {
        //翻转代替旋转
        int n = matrix.size();
        //水平翻转
        for (int i = 0; i < n / 2; i++)
        {
            for (int j = 0; j < n; j++)
            {
                //[i][j]-->[n-i-1][j]-->[j][n-i-1]  
                //对应：对于矩阵中的[i][j]元素 旋转后 它的位置为[j][n-i-1]
                swap(matrix[i][j], matrix[n - i - 1][j]);
            }
        }

        //主对角线翻转
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < i; j++)
            {
                swap(matrix[i][j], matrix[j][i]);
            }
        }

    }
;
